var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var jsonmin = require('gulp-jsonmin');
var del = require('del');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');

var dist = 'dist';

gulp.task('clean', function () {
    return del([dist]);
});

gulp.task('zs', function () {
    return gulp.src(['src/**/*'])
        .pipe(gulpif(file => file.extname == '.js' && !/\.min\.js/.test(file.path), uglify()))
        .pipe(gulpif(file => file.extname == '.html', htmlmin({
            removeComments: true,  //清除HTML注释
            collapseWhitespace: true,  //压缩HTML
            minifyJS: true,  //压缩页面JS
            minifyCSS: true  //压缩页面CSS
        })))
        .pipe(gulpif(file => file.extname == '.json', jsonmin()))
        .pipe(gulp.dest(dist));
});

gulp.task('default', gulp.series('clean', 'zs'));